<!--
 * @Description: 监测月报
 * @Author: Ronda
 * @Date: 2022-02-16 09:30:08
 * @LastEditors: Ronda
 * @LastEditTime: 2022-05-23 15:20:05
-->
<template>
  <div>
    <el-row>
      <el-col :span="6">
        <div class="empData" style="padding-right:10px;border-right:1px solid #ccc;height:calc(100vh - 60px)">
          <el-input placeholder="输入关键字进行过滤" v-model="filterText">
          </el-input>
          <el-tree @node-click="handlerClick" class="filter-tree" :data="data" :props="defaultProps"
            :filter-node-method="filterNode" ref="tree">
          </el-tree>
        </div>
      </el-col>
      <el-col :span="16">
        <div v-if="params.device_id" class="table" style="margin-left:10px ">
          <template>
            <!-- Tabs 标签页 点击只看某个属性 -->
            <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="tsp" name="first">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                     
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="tsp" label="tsp" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>

              </el-tab-pane>
              <el-tab-pane label="pm10" name="second">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                     
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="pm10" label="pm10" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
              <el-tab-pane label="pm25" name="third">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                    
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="pm25" label="pm25" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
              <el-tab-pane label="湿度" name="fourth">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                     
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="humidity" label="湿度" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
              <el-tab-pane label="温度" name="fifth">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                     
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="temperature" label="温度" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
              <el-tab-pane label="风向" name="sixth">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                     
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="wind_direction" label="风向" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
              <el-tab-pane label="风速" name="seventh">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                    
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="wind_speed" label="风速" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
              <el-tab-pane label="噪音" name="eighth">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                    
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="noise" label="噪音" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>

              <el-tab-pane label="所有" name="ninth">
                <template slot-scope='scope'>
                  <div class="content">
                    <el-table :data="empData" style="width: 100%">
                     
                      <el-table-column prop="insert_time" label="时间" width="80">
                        <template slot-scope='scope'>
                          <div>
                            {{ scope.row.insert_time | fmtTime }}
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="tsp" label="tsp" width="70">
                      </el-table-column>
                      <el-table-column prop="pm10" label="pm10" width="70">
                      </el-table-column>
                      <el-table-column prop="pm25" label="pm25" width="70">
                      </el-table-column>
                      <el-table-column prop="temperature" label="温度" width="70">
                      </el-table-column>
                      <el-table-column prop="humidity" label="湿度" width="70">
                      </el-table-column>
                      <el-table-column prop="wind_direction" label="风向" width="70">
                      </el-table-column>
                      <el-table-column prop="wind_speed" label="风速" width="70">
                      </el-table-column>
                      <el-table-column prop="noise" label="噪音" width="70">
                      </el-table-column>
                    </el-table>
                  </div>
                </template>
              </el-tab-pane>
            </el-tabs>
          </template>
          <div class="page" style="margin-top:15px;text-align:right">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="params.page" :page-sizes="[10]" :page-size="params.pageSize"
              layout="total, sizes" :total="total" hide-on-single-page>
            </el-pagination>
          </div>



        </div>
        <div v-else style="color:red;text-align:left">请选择设备</div>
      </el-col>
     
    </el-row>
  </div>
</template>

<script>
import { get } from '@/utils/request'
export default {
  data() {
    return {
      activeName: 'second',
      // 设备数据
      empData: [],
      // 过滤文本
      filterText: '',
      // 树形结构数据源
      data: [],
      // 树形结构配置项
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      //  params1: {
      //    page: 1,
      //    pageSize: 10
      //  },
      total: 0,
      params: {
        page: 1,
        pageSize: 12,
        engineer_id: "",
        device_id: "",
      },

    };
  },
  watch: {
    // 监听文本进行过滤 
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  computed: {},
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    toSearch() {
      this.getEmpData();
    },
    // 点击树形节点
    handlerClick(data) {
      // data 点击工程 data---工程数据 children
      // data 点击设备 data---设备数据 没有children
      // 判断点击的是设备
      if (!data.children) {
        this.params.engineer_id = data.engineer_id;
        this.params.device_id = data.id;
      }
      this.getEmpData();
    },

    // 获取工程设备采集的数据--右侧数据
    async getEmpData() {
      // params page pageSize device_id e_id

      let res = await get('/monitor/pageQuery', this.params);
      this.empData = res.data.list;
      this.total = res.data.total;
    },
    // 获取工程设备 --左侧用到数据
    async loadEmpData() {
      let res = await get('/engineer/findEngineerDeviceTree');
      this.data = res.data;
    },
    // 过滤节点的方法
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
      // return data.name.indexOf(value) !== -1;
    },

    // 数据条数发生变化函数
    handleSizeChange(pageSize) {
      // console.log(pageSize,'条数');
      // 当条数发生改变 重新请求工程数据
      // params.pageSize --->2 
      this.params1.pageSize = pageSize;
      // 重新请求工程数据
      this.getEmpData();
    },
    // 页码发生改变函数
    handleCurrentChange(page) {
      // console.log(page,'当前页码');
      this.params1.page = page;
      this.getEmpData();
    }
  },
  created() {
    this.loadEmpData();
    this.getEmpData();

  },
  mounted() { },
};
</script>
<style scoped></style>